﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WebPattern.Core
{
    public class Role : IEquatable<Role>
    {
        #region Properties
        public virtual int Id { set; get; }
        public virtual string Name { set; get; }
        public virtual string ApplicationName { set; get; }
        public virtual string Description { set; get; }
        public virtual bool Enabled { set; get; }

        public virtual ICollection<User> UsersInRole { set; get; }
        #endregion

        #region Constructors
        public Role()
        {
            this.Enabled = true;
        }

        public Role(string roleName)
            : this()
        {
            this.Name = roleName;
        }

        public Role(string roleName, string applicationName)
            : this(roleName)
        {
            this.ApplicationName = applicationName;
        }
        #endregion

        #region Overriden Methods
        public override bool Equals(object obj)
        {
            return this.Equals(obj as Role);
        }

        public override string ToString()
        {
            return string.Format("{0}/{1}", this.ApplicationName, this.Name);
        }
        #endregion

        #region Methods
        public virtual bool Equals(Role other)
        {
            if (other == null)
                return false;

            if (ReferenceEquals(this, other))
                return true;

            return this.ApplicationName == other.ApplicationName && this.Name == other.Name;
        }
        #endregion
    }
}
